package com.ruoyi.web.controller.shpc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TGoodsSpecification;
import com.ruoyi.system.service.ITGoodsSpecificationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品规格Controller
 * 
 * @author ruoyi
 * @date 2024-02-25
 */
@RestController
@RequestMapping("/shpc/specification")
public class TGoodsSpecificationController extends BaseController
{
    @Autowired
    private ITGoodsSpecificationService tGoodsSpecificationService;

    /**
     * 查询产品规格列表
     */
    @PreAuthorize("@ss.hasPermi('shpc:specification:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGoodsSpecification tGoodsSpecification)
    {
        startPage();
        List<TGoodsSpecification> list = tGoodsSpecificationService.selectTGoodsSpecificationList(tGoodsSpecification);
        return getDataTable(list);
    }

    /**
     * 导出产品规格列表
     */
    @PreAuthorize("@ss.hasPermi('shpc:specification:export')")
    @Log(title = "产品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TGoodsSpecification tGoodsSpecification)
    {
        List<TGoodsSpecification> list = tGoodsSpecificationService.selectTGoodsSpecificationList(tGoodsSpecification);
        ExcelUtil<TGoodsSpecification> util = new ExcelUtil<TGoodsSpecification>(TGoodsSpecification.class);
        util.exportExcel(response, list, "产品规格数据");
    }

    /**
     * 获取产品规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('shpc:specification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tGoodsSpecificationService.selectTGoodsSpecificationById(id));
    }

    /**
     * 新增产品规格
     */
    @PreAuthorize("@ss.hasPermi('shpc:specification:add')")
    @Log(title = "产品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TGoodsSpecification tGoodsSpecification)
    {
        return toAjax(tGoodsSpecificationService.insertTGoodsSpecification(tGoodsSpecification));
    }

    /**
     * 修改产品规格
     */
    @PreAuthorize("@ss.hasPermi('shpc:specification:edit')")
    @Log(title = "产品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGoodsSpecification tGoodsSpecification)
    {
        return toAjax(tGoodsSpecificationService.updateTGoodsSpecification(tGoodsSpecification));
    }

    /**
     * 删除产品规格
     */
    @PreAuthorize("@ss.hasPermi('shpc:specification:remove')")
    @Log(title = "产品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tGoodsSpecificationService.deleteTGoodsSpecificationByIds(ids));
    }
}
